package fi.helsinki.cs.scheduler3000;

/**
 * @author Team TA's
 */
import java.util.ArrayList;
import java.util.HashMap;

import fi.helsinki.cs.scheduler3000.Weekday.Day;

public class DayReport extends Report {

    public DayReport(Schedule schedule,
            HashMap<String, Object> options) {
        super(schedule, options);
    }

    /**
     * Konstruktori luo DayReport -olion
     * @param schedule aikataulu, josta raportti luodaan
     * @param options aikajänne, jolta raportti luodaan
     */
    @Override
    public String toString() {
        if (this.options.containsKey("day")) {
            StringBuilder sb = new StringBuilder();
            Weekday.Day weekday = (Day) this.options.get("day");
            ArrayList<Event> events = this.schedule.getSchedule().get(weekday);

            if (events == null) {
                return null;
            }

            sb.append(Weekday.longNameMap.get(weekday));
            sb.append(":\n------\n");

            for (Event e : events) {
                if (e.getTitle().equals("")) {
                    sb.append("<no title for this event>");
                } else {
                    sb.append(e.getTitle());
                }

                //event must always have start time and end time
                sb.append("\nat ");
                sb.append(e.getStartTime());
                sb.append(" to ");
                sb.append(e.getEndTime());

                if (e.getLocation().equals("")) {
                    sb.append("\n<no location specified>");
                } else {
                    sb.append("\nin ");
                    sb.append(e.getLocation());
                }
                sb.append("\n\n");
            }
            return sb.toString();
        }

        return null;
    }
}
